{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import time\n",
    "import errno"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "s3 = pd.Series({'语文':90,'数学':92,'英语':98,'物理':87,'化学':92})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'英语'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3.idxmax()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'物理'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3.idxmin()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "数学    92\n",
       "英语    98\n",
       "化学    92\n",
       "dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3[s3>90]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = {'城市':['北京','上海','广州','深圳'],\n",
    "        '环比':[101.5,101.2,101.3,102.0],\n",
    "        '同比':[120.7,127.3,119.4,140.9],\n",
    "        '定基':[121.4,127.8,120.0,145.5]}\n",
    "pd1 = pd.DataFrame(data,index=['c1','c2','c3','c4'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>环比</th>\n",
       "      <th>同比</th>\n",
       "      <th>定基</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>c1</td>\n",
       "      <td>北京</td>\n",
       "      <td>101.5</td>\n",
       "      <td>120.7</td>\n",
       "      <td>121.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c2</td>\n",
       "      <td>上海</td>\n",
       "      <td>101.2</td>\n",
       "      <td>127.3</td>\n",
       "      <td>127.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c3</td>\n",
       "      <td>广州</td>\n",
       "      <td>101.3</td>\n",
       "      <td>119.4</td>\n",
       "      <td>120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c4</td>\n",
       "      <td>深圳</td>\n",
       "      <td>102.0</td>\n",
       "      <td>140.9</td>\n",
       "      <td>145.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    城市     环比     同比     定基\n",
       "c1  北京  101.5  120.7  121.4\n",
       "c2  上海  101.2  127.3  127.8\n",
       "c3  广州  101.3  119.4  120.0\n",
       "c4  深圳  102.0  140.9  145.5"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "c1    120.7\n",
       "c2    127.3\n",
       "c3    119.4\n",
       "c4    140.9\n",
       "Name: 同比, dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1['同比']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(pd1[1:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(pd1.loc['c2'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>同比</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>c1</td>\n",
       "      <td>北京</td>\n",
       "      <td>120.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c2</td>\n",
       "      <td>上海</td>\n",
       "      <td>127.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c4</td>\n",
       "      <td>深圳</td>\n",
       "      <td>140.9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    城市     同比\n",
       "c1  北京  120.7\n",
       "c2  上海  127.3\n",
       "c4  深圳  140.9"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1.iloc[:,[0,2]][pd1.iloc[:,2]>120]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>同比</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>c1</td>\n",
       "      <td>北京</td>\n",
       "      <td>120.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c2</td>\n",
       "      <td>上海</td>\n",
       "      <td>127.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c4</td>\n",
       "      <td>深圳</td>\n",
       "      <td>140.9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    城市     同比\n",
       "c1  北京  120.7\n",
       "c2  上海  127.3\n",
       "c4  深圳  140.9"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1.loc[:,['城市','同比']][pd1.loc[:,'同比']>120]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>环比</th>\n",
       "      <th>同比</th>\n",
       "      <th>定基</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>c1</td>\n",
       "      <td>北京</td>\n",
       "      <td>101.5</td>\n",
       "      <td>120.7</td>\n",
       "      <td>121.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c2</td>\n",
       "      <td>上海</td>\n",
       "      <td>101.2</td>\n",
       "      <td>127.3</td>\n",
       "      <td>127.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c3</td>\n",
       "      <td>广州</td>\n",
       "      <td>101.3</td>\n",
       "      <td>119.4</td>\n",
       "      <td>120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c4</td>\n",
       "      <td>深圳</td>\n",
       "      <td>102.0</td>\n",
       "      <td>140.9</td>\n",
       "      <td>145.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    城市     环比     同比     定基\n",
       "c1  北京  101.5  120.7  121.4\n",
       "c2  上海  101.2  127.3  127.8\n",
       "c3  广州  101.3  119.4  120.0\n",
       "c4  深圳  102.0  140.9  145.5"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd1['评价指数']=100.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>环比</th>\n",
       "      <th>同比</th>\n",
       "      <th>定基</th>\n",
       "      <th>评价指数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>c1</td>\n",
       "      <td>北京</td>\n",
       "      <td>101.5</td>\n",
       "      <td>120.7</td>\n",
       "      <td>121.4</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c2</td>\n",
       "      <td>上海</td>\n",
       "      <td>101.2</td>\n",
       "      <td>127.3</td>\n",
       "      <td>127.8</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c3</td>\n",
       "      <td>广州</td>\n",
       "      <td>101.3</td>\n",
       "      <td>119.4</td>\n",
       "      <td>120.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c4</td>\n",
       "      <td>深圳</td>\n",
       "      <td>102.0</td>\n",
       "      <td>140.9</td>\n",
       "      <td>145.5</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    城市     环比     同比     定基   评价指数\n",
       "c1  北京  101.5  120.7  121.4  100.0\n",
       "c2  上海  101.2  127.3  127.8  100.0\n",
       "c3  广州  101.3  119.4  120.0  100.0\n",
       "c4  深圳  102.0  140.9  145.5  100.0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>环比</th>\n",
       "      <th>同比</th>\n",
       "      <th>定基</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>c1</td>\n",
       "      <td>北京</td>\n",
       "      <td>101.5</td>\n",
       "      <td>120.7</td>\n",
       "      <td>121.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c2</td>\n",
       "      <td>上海</td>\n",
       "      <td>101.2</td>\n",
       "      <td>127.3</td>\n",
       "      <td>127.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c3</td>\n",
       "      <td>广州</td>\n",
       "      <td>101.3</td>\n",
       "      <td>119.4</td>\n",
       "      <td>120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>c4</td>\n",
       "      <td>深圳</td>\n",
       "      <td>102.0</td>\n",
       "      <td>140.9</td>\n",
       "      <td>145.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    城市     环比     同比     定基\n",
       "c1  北京  101.5  120.7  121.4\n",
       "c2  上海  101.2  127.3  127.8\n",
       "c3  广州  101.3  119.4  120.0\n",
       "c4  深圳  102.0  140.9  145.5"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1.drop(labels='评价指数',axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = {'数据信息学院':np.random.randint(1,100,10),\n",
    "        '文化教育学院':np.random.randint(1,100,10),\n",
    "        '机电汽修学院':np.random.randint(1,100,10)}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'数据信息学院': array([28, 15, 56, 59, 18,  7, 88, 59, 90, 11]),\n",
       " '文化教育学院': array([38,  3, 72,  6, 27, 26, 66, 45, 32, 30]),\n",
       " '机电汽修学院': array([84, 67, 26, 43, 93, 50, 87, 24, 86, 82])}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "date = pd.date_range(start='202010100800',end='202010101700',freq='H')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2020-10-10 08:00:00', '2020-10-10 09:00:00',\n",
       "               '2020-10-10 10:00:00', '2020-10-10 11:00:00',\n",
       "               '2020-10-10 12:00:00', '2020-10-10 13:00:00',\n",
       "               '2020-10-10 14:00:00', '2020-10-10 15:00:00',\n",
       "               '2020-10-10 16:00:00', '2020-10-10 17:00:00'],\n",
       "              dtype='datetime64[ns]', freq='H')"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd3 = pd.DataFrame(data,index=date)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>数据信息学院</th>\n",
       "      <th>文化教育学院</th>\n",
       "      <th>机电汽修学院</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>2020-10-10 08:00:00</td>\n",
       "      <td>28</td>\n",
       "      <td>38</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2020-10-10 09:00:00</td>\n",
       "      <td>15</td>\n",
       "      <td>3</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2020-10-10 10:00:00</td>\n",
       "      <td>56</td>\n",
       "      <td>72</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2020-10-10 11:00:00</td>\n",
       "      <td>59</td>\n",
       "      <td>6</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2020-10-10 12:00:00</td>\n",
       "      <td>18</td>\n",
       "      <td>27</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2020-10-10 13:00:00</td>\n",
       "      <td>7</td>\n",
       "      <td>26</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2020-10-10 14:00:00</td>\n",
       "      <td>88</td>\n",
       "      <td>66</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2020-10-10 15:00:00</td>\n",
       "      <td>59</td>\n",
       "      <td>45</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2020-10-10 16:00:00</td>\n",
       "      <td>90</td>\n",
       "      <td>32</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2020-10-10 17:00:00</td>\n",
       "      <td>11</td>\n",
       "      <td>30</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     数据信息学院  文化教育学院  机电汽修学院\n",
       "2020-10-10 08:00:00      28      38      84\n",
       "2020-10-10 09:00:00      15       3      67\n",
       "2020-10-10 10:00:00      56      72      26\n",
       "2020-10-10 11:00:00      59       6      43\n",
       "2020-10-10 12:00:00      18      27      93\n",
       "2020-10-10 13:00:00       7      26      50\n",
       "2020-10-10 14:00:00      88      66      87\n",
       "2020-10-10 15:00:00      59      45      24\n",
       "2020-10-10 16:00:00      90      32      86\n",
       "2020-10-10 17:00:00      11      30      82"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                     数据信息学院  文化教育学院  机电汽修学院\n",
      "2020-10-10 08:00:00      28      38      84\n",
      "2020-10-10 09:00:00      15       3      67\n",
      "2020-10-10 10:00:00      56      72      26\n",
      "2020-10-10 11:00:00      59       6      43\n",
      "2020-10-10 12:00:00      18      27      93\n",
      "2020-10-10 13:00:00       7      26      50\n",
      "2020-10-10 14:00:00      88      66      87\n",
      "2020-10-10 15:00:00      59      45      24\n",
      "2020-10-10 16:00:00      90      32      86\n",
      "2020-10-10 17:00:00      11      30      82\n"
     ]
    }
   ],
   "source": [
    "print(pd3.resample('H').sum())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>info_id</th>\n",
       "      <th>emp_id</th>\n",
       "      <th>number_consumers</th>\n",
       "      <th>mode</th>\n",
       "      <th>dining_table_id</th>\n",
       "      <th>dining_table_name</th>\n",
       "      <th>expenditure</th>\n",
       "      <th>dishes_count</th>\n",
       "      <th>accounts_payable</th>\n",
       "      <th>use_start_time</th>\n",
       "      <th>...</th>\n",
       "      <th>lock_time</th>\n",
       "      <th>cashier_id</th>\n",
       "      <th>pc_id</th>\n",
       "      <th>order_number</th>\n",
       "      <th>org_id</th>\n",
       "      <th>print_doc_bill_num</th>\n",
       "      <th>lock_table_info</th>\n",
       "      <th>order_status</th>\n",
       "      <th>phone</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>417</td>\n",
       "      <td>1442</td>\n",
       "      <td>4</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1501</td>\n",
       "      <td>1022</td>\n",
       "      <td>165</td>\n",
       "      <td>5</td>\n",
       "      <td>165</td>\n",
       "      <td>2016/8/1 11:05:36</td>\n",
       "      <td>...</td>\n",
       "      <td>2016/8/1 11:11:46</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>330</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>18688880641</td>\n",
       "      <td>苗宇怡</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>301</td>\n",
       "      <td>1095</td>\n",
       "      <td>3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1430</td>\n",
       "      <td>1031</td>\n",
       "      <td>321</td>\n",
       "      <td>6</td>\n",
       "      <td>321</td>\n",
       "      <td>2016/8/1 11:15:57</td>\n",
       "      <td>...</td>\n",
       "      <td>2016/8/1 11:31:55</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>328</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>18688880174</td>\n",
       "      <td>赵颖</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>413</td>\n",
       "      <td>1147</td>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1488</td>\n",
       "      <td>1009</td>\n",
       "      <td>854</td>\n",
       "      <td>15</td>\n",
       "      <td>854</td>\n",
       "      <td>2016/8/1 12:42:52</td>\n",
       "      <td>...</td>\n",
       "      <td>2016/8/1 12:54:37</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>330</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>18688880276</td>\n",
       "      <td>徐毅凡</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>415</td>\n",
       "      <td>1166</td>\n",
       "      <td>4</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1502</td>\n",
       "      <td>1023</td>\n",
       "      <td>466</td>\n",
       "      <td>10</td>\n",
       "      <td>466</td>\n",
       "      <td>2016/8/1 12:51:38</td>\n",
       "      <td>...</td>\n",
       "      <td>2016/8/1 13:08:20</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>330</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>18688880231</td>\n",
       "      <td>张大鹏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>392</td>\n",
       "      <td>1094</td>\n",
       "      <td>10</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1499</td>\n",
       "      <td>1020</td>\n",
       "      <td>704</td>\n",
       "      <td>24</td>\n",
       "      <td>704</td>\n",
       "      <td>2016/8/1 12:58:44</td>\n",
       "      <td>...</td>\n",
       "      <td>2016/8/1 13:07:16</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>330</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>18688880173</td>\n",
       "      <td>孙熙凯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>940</td>\n",
       "      <td>641</td>\n",
       "      <td>1095</td>\n",
       "      <td>8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1492</td>\n",
       "      <td>1013</td>\n",
       "      <td>679</td>\n",
       "      <td>12</td>\n",
       "      <td>679</td>\n",
       "      <td>2016/8/31 21:23:48</td>\n",
       "      <td>...</td>\n",
       "      <td>2016/8/31 21:31:48</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>330</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>18688880307</td>\n",
       "      <td>李靖</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>941</td>\n",
       "      <td>672</td>\n",
       "      <td>1089</td>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1489</td>\n",
       "      <td>1010</td>\n",
       "      <td>800</td>\n",
       "      <td>24</td>\n",
       "      <td>800</td>\n",
       "      <td>2016/8/31 21:24:12</td>\n",
       "      <td>...</td>\n",
       "      <td>2016/8/31 21:56:12</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>330</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>18688880305</td>\n",
       "      <td>莫言</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>942</td>\n",
       "      <td>692</td>\n",
       "      <td>1155</td>\n",
       "      <td>8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1492</td>\n",
       "      <td>1013</td>\n",
       "      <td>735</td>\n",
       "      <td>10</td>\n",
       "      <td>735</td>\n",
       "      <td>2016/8/31 21:25:18</td>\n",
       "      <td>...</td>\n",
       "      <td>2016/8/31 21:33:34</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>330</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>18688880327</td>\n",
       "      <td>习一冰</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>943</td>\n",
       "      <td>647</td>\n",
       "      <td>1094</td>\n",
       "      <td>4</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1485</td>\n",
       "      <td>1006</td>\n",
       "      <td>262</td>\n",
       "      <td>9</td>\n",
       "      <td>262</td>\n",
       "      <td>2016/8/31 21:37:39</td>\n",
       "      <td>...</td>\n",
       "      <td>2016/8/31 21:55:39</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>330</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>18688880207</td>\n",
       "      <td>章春华</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>944</td>\n",
       "      <td>570</td>\n",
       "      <td>1113</td>\n",
       "      <td>8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1517</td>\n",
       "      <td>1038</td>\n",
       "      <td>589</td>\n",
       "      <td>13</td>\n",
       "      <td>589</td>\n",
       "      <td>2016/8/31 21:41:56</td>\n",
       "      <td>...</td>\n",
       "      <td>2016/8/31 21:32:56</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>330</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>18688880313</td>\n",
       "      <td>唐雅嘉</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>945 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     info_id  emp_id  number_consumers  mode  dining_table_id  \\\n",
       "0        417    1442                 4   NaN             1501   \n",
       "1        301    1095                 3   NaN             1430   \n",
       "2        413    1147                 6   NaN             1488   \n",
       "3        415    1166                 4   NaN             1502   \n",
       "4        392    1094                10   NaN             1499   \n",
       "..       ...     ...               ...   ...              ...   \n",
       "940      641    1095                 8   NaN             1492   \n",
       "941      672    1089                 6   NaN             1489   \n",
       "942      692    1155                 8   NaN             1492   \n",
       "943      647    1094                 4   NaN             1485   \n",
       "944      570    1113                 8   NaN             1517   \n",
       "\n",
       "     dining_table_name  expenditure  dishes_count  accounts_payable  \\\n",
       "0                 1022          165             5               165   \n",
       "1                 1031          321             6               321   \n",
       "2                 1009          854            15               854   \n",
       "3                 1023          466            10               466   \n",
       "4                 1020          704            24               704   \n",
       "..                 ...          ...           ...               ...   \n",
       "940               1013          679            12               679   \n",
       "941               1010          800            24               800   \n",
       "942               1013          735            10               735   \n",
       "943               1006          262             9               262   \n",
       "944               1038          589            13               589   \n",
       "\n",
       "         use_start_time  ...           lock_time cashier_id  pc_id  \\\n",
       "0     2016/8/1 11:05:36  ...   2016/8/1 11:11:46        NaN    NaN   \n",
       "1     2016/8/1 11:15:57  ...   2016/8/1 11:31:55        NaN    NaN   \n",
       "2     2016/8/1 12:42:52  ...   2016/8/1 12:54:37        NaN    NaN   \n",
       "3     2016/8/1 12:51:38  ...   2016/8/1 13:08:20        NaN    NaN   \n",
       "4     2016/8/1 12:58:44  ...   2016/8/1 13:07:16        NaN    NaN   \n",
       "..                  ...  ...                 ...        ...    ...   \n",
       "940  2016/8/31 21:23:48  ...  2016/8/31 21:31:48        NaN    NaN   \n",
       "941  2016/8/31 21:24:12  ...  2016/8/31 21:56:12        NaN    NaN   \n",
       "942  2016/8/31 21:25:18  ...  2016/8/31 21:33:34        NaN    NaN   \n",
       "943  2016/8/31 21:37:39  ...  2016/8/31 21:55:39        NaN    NaN   \n",
       "944  2016/8/31 21:41:56  ...  2016/8/31 21:32:56        NaN    NaN   \n",
       "\n",
       "     order_number  org_id  print_doc_bill_num  lock_table_info  order_status  \\\n",
       "0             NaN     330                 NaN              NaN             1   \n",
       "1             NaN     328                 NaN              NaN             1   \n",
       "2             NaN     330                 NaN              NaN             1   \n",
       "3             NaN     330                 NaN              NaN             1   \n",
       "4             NaN     330                 NaN              NaN             1   \n",
       "..            ...     ...                 ...              ...           ...   \n",
       "940           NaN     330                 NaN              NaN             1   \n",
       "941           NaN     330                 NaN              NaN             1   \n",
       "942           NaN     330                 NaN              NaN             1   \n",
       "943           NaN     330                 NaN              NaN             1   \n",
       "944           NaN     330                 NaN              NaN             1   \n",
       "\n",
       "           phone  name  \n",
       "0    18688880641   苗宇怡  \n",
       "1    18688880174    赵颖  \n",
       "2    18688880276   徐毅凡  \n",
       "3    18688880231   张大鹏  \n",
       "4    18688880173   孙熙凯  \n",
       "..           ...   ...  \n",
       "940  18688880307    李靖  \n",
       "941  18688880305    莫言  \n",
       "942  18688880327   习一冰  \n",
       "943  18688880207   章春华  \n",
       "944  18688880313   唐雅嘉  \n",
       "\n",
       "[945 rows x 21 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = pd.read_csv('d:/Desktop/meal_order_info.csv',encoding='gbk')\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lock_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>2016/8/1 11:11:46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2016/8/1 11:31:55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>2016/8/1 12:54:37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>2016/8/1 13:08:20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>2016/8/1 13:07:16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           lock_time\n",
       "0  2016/8/1 11:11:46\n",
       "1  2016/8/1 11:31:55\n",
       "2  2016/8/1 12:54:37\n",
       "3  2016/8/1 13:08:20\n",
       "4  2016/8/1 13:07:16"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A.iloc[:5,[11]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>use_start_time</th>\n",
       "      <th>lock_time</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>2016/8/1 11:05:36</td>\n",
       "      <td>2016/8/1 11:11:46</td>\n",
       "      <td>苗宇怡</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2016/8/1 11:15:57</td>\n",
       "      <td>2016/8/1 11:31:55</td>\n",
       "      <td>赵颖</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>2016/8/1 12:42:52</td>\n",
       "      <td>2016/8/1 12:54:37</td>\n",
       "      <td>徐毅凡</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>2016/8/1 12:51:38</td>\n",
       "      <td>2016/8/1 13:08:20</td>\n",
       "      <td>张大鹏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>2016/8/1 12:58:44</td>\n",
       "      <td>2016/8/1 13:07:16</td>\n",
       "      <td>孙熙凯</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      use_start_time          lock_time name\n",
       "0  2016/8/1 11:05:36  2016/8/1 11:11:46  苗宇怡\n",
       "1  2016/8/1 11:15:57  2016/8/1 11:31:55   赵颖\n",
       "2  2016/8/1 12:42:52  2016/8/1 12:54:37  徐毅凡\n",
       "3  2016/8/1 12:51:38  2016/8/1 13:08:20  张大鹏\n",
       "4  2016/8/1 12:58:44  2016/8/1 13:07:16  孙熙凯"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A.iloc[:5,[9,11,-1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    2016/8/1 11:11:46\n",
       "1    2016/8/1 11:31:55\n",
       "2    2016/8/1 12:54:37\n",
       "3    2016/8/1 13:08:20\n",
       "4    2016/8/1 13:07:16\n",
       "Name: lock_time, dtype: object"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A.iloc[:5,11]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2016 年 8 月 1 日 Monday\n",
      "2016 年 8 月 1 日 Monday\n",
      "2016 年 8 月 1 日 Monday\n",
      "2016 年 8 月 1 日 Monday\n",
      "2016 年 8 月 1 日 Monday\n"
     ]
    }
   ],
   "source": [
    "for i in A.iloc[:5,11]:\n",
    "    iy = pd.Timestamp(i).year\n",
    "    im = pd.Timestamp(i).month\n",
    "    iD = pd.Timestamp(i).day\n",
    "    iw = pd.Timestamp(i).day_name()\n",
    "    print(iy,'年',im,'月',iD,'日',iw)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "max 55:41 min 00:00\n"
     ]
    }
   ],
   "source": [
    "T = []\n",
    "E = []\n",
    "T1= []\n",
    "for i in range(len(A.iloc[:,11])):\n",
    "    try:\n",
    "        timea = time.strptime(A.iloc[i,11], \"%Y/%m/%d %H:%M:%S\")\n",
    "        timeb = time.mktime(timea)\n",
    "        timec = time.strptime(A.iloc[i,9], \"%Y/%m/%d %H:%M:%S\")\n",
    "        timed = time.mktime(timec)\n",
    "        Time = timeb - timed\n",
    "        Time1 = time.localtime(Time)\n",
    "        Time2 = time.strftime(\"%M:%S\",Time1)\n",
    "        T.append(Time2)\n",
    "    except (TypeError,OSError) as e:\n",
    "        E.append('有问题的行'+str(i)+str(e))\n",
    "print('max',max(T),'min',min(T))\n",
    "    #S.append(time.strptime(A.iloc[i,11]),-int(A.iloc[i,9],))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
